package org.rency.crawler.fetch.repository.impl;

import java.util.List;
import javax.annotation.Resource;
import org.rency.crawler.dal.dao.FetchStateRuleDao;
import org.rency.crawler.dal.entity.FetchStateRuleDO;
import org.rency.crawler.domain.state.FetchStateRuleDomain;
import org.rency.crawler.fetch.converter.DomainConvertor;
import org.rency.crawler.fetch.repository.FetchStateRuleRepository;
import org.springframework.stereotype.Repository;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/22 10:20<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/22 10:20
 */
@Repository
public class FetchStateRuleRepositoryImpl implements FetchStateRuleRepository {

  @Resource
  private FetchStateRuleDao fetchStateRuleDao;

  @Resource(name = "fetchStateRuleDomainConvertor")
  private DomainConvertor<FetchStateRuleDomain, FetchStateRuleDO> convertor;

  @Override
  public FetchStateRuleDomain load(String id) {
    return convertor.convertDomain(fetchStateRuleDao.load(id));
  }

  @Override
  public List<FetchStateRuleDomain> findAll() {
    return convertor.convertDomain(fetchStateRuleDao.findAll());
  }

  @Override
  public List<FetchStateRuleDomain> find(String fsCode) {
    return convertor.convertDomain(fetchStateRuleDao.find(fsCode));
  }

  @Override
  public FetchStateRuleDomain find(String fsCode, String fsStatus) {
    return convertor.convertDomain(fetchStateRuleDao.find(fsCode, fsStatus));
  }

  @Override
  public boolean save(FetchStateRuleDomain domain) {
    return fetchStateRuleDao.save(convertor.convertEntity(domain));
  }

  @Override
  public boolean updateRetryTimes(String id, int retryTimes) {
    return fetchStateRuleDao.updateRetryTimes(id, retryTimes);
  }

  @Override
  public boolean delete(String id) {
    return fetchStateRuleDao.delete(id);
  }
}
